//
//  ESActivityViewable.swift
//  SwiftBase
//
//  Created by rubick on 2023/2/13.
//

import UIKit
import Foundation
import NVActivityIndicatorView

public protocol RKActivityViewable { }
public extension RKActivityViewable where Self: UIViewController {
    var isAnimating:Bool { return RKActivityPresenter.sharedInstance.isAnimating }
    func startAnimating(
        _ size: CGSize? = nil,
        message: String? = nil,
        messageFont: UIFont? = nil,
        type: NVActivityIndicatorType? = nil,
        color: UIColor? = nil,
        padding: CGFloat? = nil,
        displayTimeThreshold: Int? = nil,
        minimumDisplayTime: Int? = nil,
        backgroundColor: UIColor? = nil,
        textColor: UIColor? = nil,
        fadeInAnimation: FadeInAnimation? = NVActivityIndicatorView.DEFAULT_FADE_IN_ANIMATION
    ) {
        let activityData = RKActivityData(
            size: size,
            message: message,
            messageFont: messageFont,
            type: type,
            color: color,
            textColor: textColor,
            padding: padding,
            displayTimeThreshold: displayTimeThreshold,
            minimumDisplayTime: minimumDisplayTime,
            backgroundColor: backgroundColor
        )
        RKActivityPresenter.sharedInstance.startAnimating(activityData, fadeInAnimation)
    }
    //
    func stopAnimating(_ fadeOutAnimation: FadeOutAnimation? = NVActivityIndicatorView.DEFAULT_FADE_OUT_ANIMATION) {
        RKActivityPresenter.sharedInstance.stopAnimating(fadeOutAnimation)
    }
}
